package com.ternnetwork.core.dao.impl;



import java.util.List;

import org.springframework.stereotype.Repository;

import com.ternnetwork.persistence.dao.impl.IBaseDaoImpl;
import com.ternnetwork.core.dao.ResourcesDao;
import com.ternnetwork.core.entity.Resources;





@Repository("resourcesDao")
public class ResourcesDaoImpl extends IBaseDaoImpl<Resources> implements ResourcesDao {
	@Override
	public List<Resources>findChild(long id){
		return findAll("from Resources t where t.parentId=?1",id);
	}
	@Override
	public List<Resources> findAllChild(List<Resources> oriList,long id){
		Resources tr=new Resources();
		tr.setId(id);
		oriList.add(tr);
		List<Resources> list=findChild(id);
		for(Resources t:list){
			oriList.addAll(findAllChild(oriList,t.getId()));
		}
		return oriList;
	}
	@Override
	public List<Resources> findAllParent(List<Resources> oriList,long id){
		Resources t=findById(Resources.class, id);
		oriList.add(t);
		if(t.getParentId()!=0){
			oriList.addAll(findAllParent(oriList,t.getParentId()));
		}
		return oriList;
	}
	
}
